<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-perAppraisalInfo-add">

        <div class="row">
            <div class="col-sm-12">
                <div class="ibox">
                    <div class="ibox-title">
                        <span  th:text="${appraisalInfo.name}" ></span>
                    </div>
                    <div class="ibox-content" >
                        <input type="hidden" id="size" th:value="${specList.size()}"/>
                        <input type="hidden" id="pkid" th:value="${appraisalInfo.pkid}"/>
                        <div class="row" th:each="spec,status:${specList}">
                            <div class="col-sm-12">
                                <div class="panel panel-default">
                                    <div class="panel-heading" >
                                        <div class="row" >
                                            <div class="col-md-3" >
                                                <label  class="control-label"   th:text="${spec.templateSpec.specName}"></label>
                                            </div>
                                            <div class="col-md-2" style="text-align: right"><label  class="control-label">权重(%):</label> </div>
                                            <div class="col-md-1">
                                                <label   class="control-label"  th:id="'weight'+${status.index}" name="weight" th:text="${spec.actualWeight}"></label>
                                                <input type="hidden" th:id="'pkid'+${status.index}" th:value="${spec.pkid}"/>
                                            </div>

                                            <div class="col-md-2" style="text-align: right">
                                                <label   class="control-label"  >自评分数：</label>
                                            </div>
                                            <div class="col-md-1">
                                                <input type="text" class="form-control" onchange="caclScore()" required th:id="'selfScore'+${status.index}" th:value="${spec.selfScore}"
                                                       th:readonly="${appraisalInfo.status!='enabled'}">
                                            </div>
                                            <div th:if="${appraisalInfo.status=='staffCompleteEvaluation'}">
                                            <div class="col-md-2" style="text-align: right">
                                                <label   class="control-label"  >评价分数：</label>
                                            </div>
                                            <div class="col-md-1">
                                                <input type="text" class="form-control" onchange="caclLeaderScore()" required th:id="'leaderScore'+${status.index}" th:value="${spec.leaderScore}"
                                                       th:readonly="${appraisalInfo.status!='staffCompleteEvaluation'}">
                                            </div>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="panel-body" >
                                        <div class="row" >
                                            <div class="col-md-6" >
                                                <label  class="control-label"   th:text="${spec.actualSpecContent}"></label>
                                            </div>
                                            <div class="col-md-6">
                                                <textarea class="form-control" rows="4" required th:id="'selfEvaluation'+${status.index}" th:text="${spec.selfEvaluation}"
                                                          th:readonly="${appraisalInfo.status!='enabled'}"></textarea>
                                            </div>
                                        </div>
                                    </div>

                                </div>
                            </div>
                        </div>


                        <div class="row" >
                            <div class="col-sm-12">
                                <div class="panel panel-default">
                                    <div class="panel-heading" >
                                        <div class="row" >
                                            <div class="col-md-10" >
                                                <label  class="control-label"  >综合自评</label>
                                            </div>

                                            <div class="col-md-2" style="text-align: right">
                                                <label   class="control-label"  id="finalSelfScore" th:text="${appraisalInfo.finalSelfScore}"></label>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="panel-body" >
                                        <div class="row" >
                                            <div class="col-md-2" >
                                                <label  class="control-label"   >请填写综合自评</label>
                                            </div>
                                            <div class="col-md-10">
                                                <textarea class="form-control" required rows="4" id="finalSelfEvaluation"
                                                          th:readonly="${appraisalInfo.status!='enabled'}"
                                                          th:text="${appraisalInfo.finalSelfEvaluation}" ></textarea>
                                            </div>
                                        </div>
                                    </div>

                                </div>
                            </div>
                        </div>
                        <div class="row" th:if="${appraisalInfo.status=='staffCompleteEvaluation'}">
                            <div class="col-sm-12">
                                <div class="panel panel-default">
                                    <div class="panel-heading" >
                                        <div class="row" >
                                            <div class="col-md-10" >
                                                <label  class="control-label"  >上级评价</label>
                                            </div>

                                            <div class="col-md-2" style="text-align: right">
                                                <label   class="control-label"  id="finalLeaderScore" th:text="${appraisalInfo.finalLeaderScore}"></label>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="panel-body" >
                                        <div class="row" >
                                            <div class="col-md-2" >
                                                <label  class="control-label"   >请填写综合评价</label>
                                            </div>
                                            <div class="col-md-10">
                                                <textarea class="form-control" required rows="4" id="finalLeaderEvaluation"
                                                          th:text="${appraisalInfo.finalLeaderEvaluation}" ></textarea>
                                            </div>
                                        </div>
                                    </div>

                                </div>
                            </div>
                        </div>

                    </div>



                </div>

            </div>
        </div>
    </form>
</div>
<div class="col-sm-12 search-collapse">
    <form id="formId">
        <div class="select-list">
            <ul>
                <li class="col-sm-7">
                </li>
                <li class="col-sm-3" th:if="${appraisalInfo.status=='enabled'}">
                    <a class="btn btn-primary btn-rounded btn-sm" onclick="saveHandler()"><i class="fa fa-search"></i>&nbsp;保存</a>
                    <a class="btn btn-warning btn-rounded btn-sm" onclick="submitHandler()"><i class="fa fa-refresh"></i>&nbsp;提交</a>
                </li>
                <li class="col-sm-3" th:if="${appraisalInfo.status=='staffCompleteEvaluation'}">
                    <a class="btn btn-primary btn-rounded btn-sm" onclick="leaderSaveOrSubmitHandler('staffCompleteEvaluation')"><i class="fa fa-search"></i>&nbsp;保存</a>
                    <a class="btn btn-warning btn-rounded btn-sm" onclick="leaderSaveOrSubmitHandler('completeEvaluation')"><i class="fa fa-refresh"></i>&nbsp;提交</a>
                </li>
            </ul>
        </div>
    </form>
</div>
<div th:include="include::footer"></div>
<script th:inline="javascript">

    var prefix = ctx + "performance/perAppraisalInfo"
    $("#form-perAppraisalInfo-add").validate({
        rules:{
            xxxx:{
                required:true,
            },
        },
        focusCleanup: true
    });
    function submitHandler() {
        if ($.validate.form()) {
            var size=$('#size').val();
            var re =  /^[0-9]+$/;
            var specs=[];
            var sumScore=0;
            for(var i=0;i<size;i++){
                var score=$('#selfScore'+i).val();
                var weight=parseInt($('#weight'+i).text());
                if (!re.test(score)){
                    $.modal.alert('自评分数必须为0-100的正整数');
                    return ;
                }
                if(score>100||score<0){
                    $.modal.alert('自评分数必须为0-100的正整数');
                    return ;
                }
                sumScore+=parseFloat((score*weight/100).toFixed(1));
                var spec={};
                spec['selfScore']=$('#selfScore'+i).val();
                spec['selfEvaluation']=$('#selfEvaluation'+i).val();
                spec['pkid']=$('#pkid'+i).val();
                specs.push(JSON.stringify(spec));
            }
            var info={};
            info['finalSelfEvaluation']=$('#finalSelfEvaluation').val();
            info['finalSelfScore']=sumScore;
            info['pkid']=$('#pkid').val();
            info['specInfos']='['+specs+']';
            info['status']='staffCompleteEvaluation';
            $.operate.saveTab(prefix + "/saveSelfEvaluation",info);
        }
    }
    function  saveHandler() {
        var size=$('#size').val();
        var re =  /^[0-9]+$/;
        var specs=[];
        var sumScore=0;
        for(var i=0;i<size;i++){
            var score=$('#selfScore'+i).val();
            var weight=parseInt($('#weight'+i).text());
            if (!re.test(score)){
                $.modal.alert('自评分数必须为0-100的正整数');
                return ;
            }
            if(score>100||score<0){
                $.modal.alert('自评分数必须为0-100的正整数');
                return ;
            }
            sumScore+=parseFloat((score*weight/100).toFixed(1));
            var spec={};
            spec['selfScore']=$('#selfScore'+i).val();
            spec['selfEvaluation']=$('#selfEvaluation'+i).val();
            spec['pkid']=$('#pkid'+i).val();
            specs.push(JSON.stringify(spec));
        }
        var info={};
        info['finalSelfEvaluation']=$('#finalSelfEvaluation').val();
        info['finalSelfScore']=sumScore;
        info['pkid']=$('#pkid').val();
        info['specInfos']='['+specs+']';
        info['status']='enabled';
        $.operate.saveTab(prefix + "/saveSelfEvaluation",info);
    }

    function  leaderSaveOrSubmitHandler(status) {
        var size=$('#size').val();
        var re =  /^[0-9]+$/;
        var specs=[];
        var sumScore=0;
        for(var i=0;i<size;i++){
            var score=$('#leaderScore'+i).val();
            var weight=parseInt($('#weight'+i).text());
            if (!re.test(score)){
                $.modal.alert('自评分数必须为0-100的正整数');
                return ;
            }
            if(score>100||score<0){
                $.modal.alert('自评分数必须为0-100的正整数');
                return ;
            }
            sumScore+=parseFloat((score*weight/100).toFixed(1));
            var spec={};
            spec['leaderScore']=$('#leaderScore'+i).val();
            spec['leaderEvaluation']=$('#leaderEvaluation'+i).val();
            spec['pkid']=$('#pkid'+i).val();
            specs.push(JSON.stringify(spec));
        }
        var info={};
        info['finalLeaderEvaluation']=$('#finalLeaderEvaluation').val();
        info['finalLeaderScore']=sumScore;
        info['pkid']=$('#pkid').val();
        info['specInfos']='['+specs+']';
        info['status']=status;
        $.operate.saveTab(prefix + "/saveSelfEvaluation",info);
    }

    function caclScore(){
        var size=$('#size').val();
        var re =  /^[0-9]+$/;
        var sumScore=0;
        for(var i=0;i<size;i++){
            var score=$('#selfScore'+i).val();
            var weight=parseInt($('#weight'+i).text());
            if (!re.test(score)){
                $.modal.alert('自评分数必须为0-100的正整数');
                return ;
            }
            if(score>100||score<0){
                $.modal.alert('自评分数必须为0-100的正整数');
                return ;
            }
            sumScore+=parseFloat((score*weight/100).toFixed(1));
        }
        $('#finalSelfScore').text(sumScore);
    }
    
    function caclLeaderScore() {
        var size=$('#size').val();
        var re =  /^[0-9]+$/;
        var sumScore=0;
        for(var i=0;i<size;i++){
            var score=$('#leaderScore'+i).val();
            var weight=parseInt($('#weight'+i).text());
            if (!re.test(score)){
                $.modal.alert('自评分数必须为0-100的正整数');
                return ;
            }
            if(score>100||score<0){
                $.modal.alert('自评分数必须为0-100的正整数');
                return ;
            }
            sumScore+=parseFloat((score*weight/100).toFixed(1));
        }
        $('#finalLeaderScore').text(sumScore);
    }
</script>
</body>
</html>
